﻿@model XPressify.Models.DetailsEventModel
@using XPressify.Data.Helpers
@using XPressify.Models
@using Omu.Awesome.Core;
@using Omu.Awesome.Mvc.Helpers;
@using XPressify.Controllers


@{
    ViewBag.Title = Model.Name;
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@if (Model.IsMemberOf || Model.IsOrganizitor || Model.EventPrivacyType == SubjectPrivacy.Public)
{
<fieldset>
    <legend style="font-size:x-large;color:#222">@Model.Name</legend>
    
    <table border="0">
        <tr>
            <td>
                @if (Model.HasCoverPicture)
                {
                    <a href='@Url.Action("AlbumDetails", "Album", new { id = Model.WallAlbumId })' class="nobtn">
                        <img src="@Model.WallAlbumCoverPath" alt="Cover" title="Cover" style="width:150px;height:150px"/>
                    </a>
                }
                else
                {
                    <a href='@Url.Action("AlbumDetails", "Album", new { id = Model.WallAlbumId })' class="nobtn">
                        Album
                    </a>
                }
            </td>
            <td style="text-align:right;width:150px;vertical-align:top">
                @if (Model.IsMemberOf)
                {
                   @Html.Confirm("Are you sure you want to remove yourself from this event?", "myconfirmBtn", title: "Remove event", yesText: "Remove") 
                        
                    using (Html.BeginForm("EventRemove", "Event", FormMethod.Post, new { style = "width:150px;font-weight:normal" }))
              {
                                @Html.HiddenFor(model => model.Id)
                                <input type="submit" value="Leave" style="font-weight:normal" class="myconfirmBtn" id="nounderline" onmouseover="changeIdToObject(this)" onmouseout="changeIdToObject(this)"/>
              }
                } 
                @if (Model.IsOrganizitor)
                {
                    @Html.Confirm("Are you sure you want to delete this event?", "myconfirmBtn", title: "Delete event", yesText: "Delete") 
                        
               using (Html.BeginForm("EventDelete", "Event", FormMethod.Post, new { style = "width:150px" }))
               {
                                @Html.HiddenFor(model => model.Id)
                                <input type="submit" value="x" class="myconfirmBtn" id="nounderline" onmouseover="changeIdToObject(this)" onmouseout="changeIdToObject(this)"/>
               }

                }
                @if (!Model.IsMemberOf && !Model.IsOrganizitor)
                {
                    @Html.ActionLink("Join", "BecomeMember", "Event", new { id = Model.Id }, new { @class = "abtn" })
                }
            </td>
        </tr>
        <tr>
            <td style="text-align: left;vertical-align:bottom">
                @if (Model.IsOrganizitor)
                {   
                    @(Html.MakePopupForm<EventController>(o => o.EventEdit(Model.Id), title: "Edit", height: 710, width: 700, okText: "Save", resizable: false, refreshOnSuccess: true))
                    @(Html.PopupFormActionLink<EventController>(o => o.EventEdit(Model.Id), "Edit", new { @class = "nobtn" }))
                }
            </td>
            <td >
                
            </td>
        </tr>
    </table>

    <table style="font-weight:bold;font-size:15px">
        <tr>
            <td>
                Time:
            </td>
            <td style="font-weight:normal;color:#222">
                @Model.StartDate.ToString("dddd, dd MMMM, yyyy a't' HH:mm") - @Model.EndDate.ToString("dd MMMM, yyyy a't' HH:mm")
            </td>
        </tr>
        <tr>
            <td>
                Location:
            </td>
            <td style="font-weight:normal;color:#222">
                @Model.Location
            </td>
        </tr>
        <tr>
            <td>
                Created by:
            </td>
            <td style="font-weight:normal;color:#222">
                @if (Model.OrganizerBlocked == false)
                {
                    @Html.ActionLink(Model.Organizer.FullName, "ProfileView", "Profile", new { id = Model.Organizer.Id }, new { @class = "nobtn" })
                }
                else
                {
                    @:Not available
                }
            </td>
        </tr>
        <tr>
            <td>
                More Info:
            </td>
            <td style="font-weight:normal;color:#222">
                @Model.Description
            </td>
        </tr>
        <tr>
            <td>
                @if (Model.EventPrivacyType == SubjectPrivacy.Public)
                {
                    @:Public event
                }
                else
                {
                    @:Private event
                }
            </td>
            <td ></td>
        </tr>
    </table>
        
    <table>
        <tr>
            <td>
                @(Html.MakePopupForm<EventController>(o => o.EventParticipants(Model.Id), title: "Participants", height: 600, width: 700, okText: "", resizable: false, refreshOnSuccess: true))
                @(Html.PopupFormActionLink<EventController>(o => o.EventParticipants(Model.Id), "Participants", new { @class = "abtn" }))
            </td>
            <td style="text-align:right">
                @if (Model.IsOrganizitor || Model.IsMemberOf)
                {
                    @(Html.MakePopupForm<EventController>(o => o.InviteFriendsToEvent(Model.Id), title: "Invite friends", height: 350, width: 350, okText: "Invite", resizable: false, refreshOnSuccess: true))
                    @(Html.PopupFormActionLink<EventController>(o => o.InviteFriendsToEvent(Model.Id), "Invite Friends", new { @class = "abtn" }))
                }
            </td>
        </tr>
    </table>

</fieldset>

if (Model.MembersCanPost || Model.IsOrganizitor)
{
    @Html.Partial("ShareLabel", new ShareLabelModel { LinkSubjectId = Model.Id, WallAlbumId = Model.WallAlbumId })

    <div id="contentHolderWrite">
        @Html.Partial("WriteStatus", new StatusCreateModel { Content = "Write something...", UserPostedOnId = Model.Id, BaseSubjectType = SubjectType.Event })    
    </div>  
}


<div id="specialPeopleLikeList" style="display:none"></div>                
@Html.Confirm("Are you sure you want to delete this post?", "myconfirmBtn", title: "Delete post", yesText: "Delete")
@Html.Confirm("Are you sure you want to delete this comment?", "myconfirmBtn1", title: "Delete comment", yesText: "Delete")
<div id="returnSuccessDelete"></div>
    
<br />

<text>______________________________________________________________________________</text>

<div id="@Model.Id"></div>    

    var specialUpdateId = "";
    foreach (var item in Model.AllPosts)
    {
    <div id="@item.Key.Id">
       <table border="0" cellpadding="0" cellspacing="0" style="margin:0px;padding:0px;width:553px">
            <tr>
                <th style="padding: 0px 2px 0px 2px;"> 
                    @Html.Raw(item.Key.Content)
                </th>
                @if (Model.IsOrganizitor || item.Key.BaseSubject.Id == Model.CurrentUser.Id || (item.Key.Creator != null && item.Key.Creator.Id == Model.CurrentUser.Id))
                {
                    <td style="padding: 0px 2px 0px 2px;vertical-align:top;background-color: #E8EEF4;text-align:right">
                        @Html.Partial("BtnPostDelete", new BtnPostDeleteModel { PostId = item.Key.Id })
                    </td>
                }
            </tr>
        </table>
   
        @foreach (var comment in item.Value)
        {   
            <div id="@comment.Id">
                <table border="0" cellpadding="0" cellspacing="0" style="margin:0px;padding:0px;width:553px">
                    <tr>
                        <th width="0px" style="padding: 0px 2px 0px 2px"> 
                            @Html.Raw(comment.Content)
                        </th>
                        @if (comment.BaseSubject.Id == Model.CurrentUser.Id || Model.IsOrganizitor)
                        {
                            <th style="padding: 0px 2px 0px 2px;vertical-align: top;text-align:right"> 
                                @Html.Partial("BtnPostCommentDelete", new BtnPostDeleteModel { PostId = comment.Id })
                            </th>
                        }
                    </tr>
                </table>
            </div>
        
        }
            
        @{specialUpdateId = item.Key.Id + "Update";}
        <div id="@specialUpdateId"></div>

        @if (item.Key.CommentType != CommentType.PostWithoutComments)
        {
            @Html.Partial("WriteComment", new PostCommentModel { PostId = item.Key.Id, ContentText = "Write a comment...", ProfilePicturePath = Model.CurrentUserProfilePicturePath })
        }
    
        ______________________________________________________________________________
    </div>
}



}